#include <queue>
#include <algorithm>
class MovingAverageFilter {
public:

    MovingAverageFilter(size_t windowSize = 5) : windowSize(windowSize), sum(0.0) {}

    double filter(double newValue) {

        windowQueue.push(newValue);
     
        double value = 0.0;
        if (windowQueue.size() > windowSize) {
            sum -= windowQueue.front();
            windowQueue.pop();
            std::cout << "sum: " << sum << std::endl;
            std::cout << "windowQueue.size():" << windowQueue.size() << std::endl;

        }
        value = (1- 0.5) * sum / windowQueue.size() + 0.5 * newValue;
        sum += newValue;
        return value;
        

    }
    void setWindowSize(size_t size) {
        windowSize = size;
    }
    void clear() {
        for(int i = 0; i < windowQueue.size(); ++i){
            windowQueue.pop();
        }
        
        sum = 0.0;
    }
private:
    size_t windowSize;
    std::queue<double> windowQueue;
    double sum;  
    double alpha = 0.6;
};